package com.it.xiaotao.concurrent;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class ConcurrentMap extends ReentrantLock {
    private String key;

    private String val;

    public void put(String key, String val) {
        System.out.println("获取锁");
        lock();
        System.out.println(Thread.currentThread().getName() + "获取到锁");
        this.key = key;
        this.val = val;
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        unlock();
    }

    public String get() {
        return this.key;
    }
}
